local funeng = fk.CreateSkill{
  name = "funeng",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["funeng"] = "赋能",
  [":funeng"] = "锁定技，游戏开始时，你选择一名其他角色，将其势力改为梦之队，并视为赋能对象。当你在摸牌阶段摸牌时，令赋能对象摸等量的牌。",

  ["@funeng"] = "王者赋能",
  ["#funeng-choose"] = "赋能：请选择要赋能的角色",
}

local updatafuneng = function (room, player, target)
  local mark = player:getTableMark("funeng")
  table.insertIfNeed(mark[2], target.id)
  room:setPlayerMark(player, "funeng", mark)
  local names = table.map(mark[2], function(pid) return Fk:translate(room:getPlayerById(pid).general) end)
  room:setPlayerMark(player, "@funeng", table.concat(names, ","))
end

funeng:addEffect(fk.GameStart, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(funeng.name) and #player.room:getOtherPlayers(player, false) > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, funeng.name)
    player:broadcastSkillInvoke(funeng.name, math.random(2))
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(player, false),
      skill_name = funeng.name,
      prompt = "#funeng-choose",
      cancelable = false,
      no_indicate = true,
    })[1]
    local mark = player:getTableMark(funeng.name)
    if #mark == 0 then mark = {{},{}} end
    table.insertIfNeed(mark[1], to.id)
    room:setPlayerMark(player, funeng.name, mark)
    room:changeKingdom(to, "dream", true)
    room:addPlayerMark(to, "@funeng", 1)
  end,
})

funeng:addEffect(fk.AfterDrawNCards, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    local mark = player:getTableMark(funeng.name)
    return not player.dead and 
    not target.dead and
    #mark > 0 and
    player:hasSkill(funeng.name) 
    and target == player 
    and table.contains(mark[1], target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to
    for _, p in ipairs(room.alive_players) do
      if p:getMark("@funeng") > 0 then
        to = p
        break
      end
    end
    if not to.dead then
      to:drawCards(data.n, funeng.name)
    end
  end,
})

return funeng
